﻿//编辑视频
EditModule_Video = function(id) {
    var EditModule_VideoForm = Ext.create("Ext.form.Panel", {
        width: 360,
        height: 450,
        autoScroll: true, 
       
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 55,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right', anchor: "90%", msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [{
                       name: "Id",
            fieldLabel: "<font color='red'>*</font>视频ID",
            allowBlank: false,
            blankText: "视频ID不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "ChannelId",
            fieldLabel: "<font color='red'>*</font>频道ID",
            allowBlank: false,
            blankText: "频道ID不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "ClassId",
            fieldLabel: "<font color='red'>*</font>栏目ID",
            allowBlank: false,
            blankText: "栏目ID不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "Title",
            fieldLabel: "<font color='red'>*</font>标题",
            allowBlank: false,
            blankText: "标题不能为空",
            regex: /^[\da-zA-Z]{1,150}$/,
            regexText: "请填写1～150个数字或字母"
        }, {
            name: "TColor",
            fieldLabel: "标题颜色",
            regex: /^[\da-zA-Z]{0,50}$/,
            regexText: "请填写0～50个数字或字母"
        }, {
            xtype:"datefield",
            name: "AddDate",
            fieldLabel: "<font color='red'>*</font>添加时间",
            allowBlank: false,
            blankText: "添加时间不能为空",
        }, {
            name: "Summary",

            fieldLabel: "<font color='red'>*</font>简介",
            allowBlank: false,
            blankText: "简介不能为空",
            regex: /^[\w]{1,2147483647}$/,
            regexText: "请填写1～2147483647个数字或字母"
         }, {
            name: "Editor",
            fieldLabel: "<font color='red'>*</font>编辑人员",
            allowBlank: false,
            blankText: "编辑人员不能为空",
            regex: /^[\da-zA-Z]{1,20}$/,
            regexText: "请填写1～20个数字或字母"
        }, {
            name: "Author",
            fieldLabel: "作者",
            regex: /^[\da-zA-Z]{0,30}$/,
            regexText: "请填写0～30个数字或字母"
        }, {
            name: "Tags",
            fieldLabel: "标签",
            regex: /^[\da-zA-Z]{0,60}$/,
            regexText: "请填写0～60个数字或字母"
        }, {
            name: "ViewNum",
            fieldLabel: "<font color='red'>*</font>查看数量",
            allowBlank: false,
            blankText: "查看数量不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "IsPass",
            fieldLabel: "是否审核",
            xtype: "combo",
            //传入后台真实值value field /value
            editable: false,
            anchor: '90%',
            value: 0,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			        { "show": "是", "value": 1 },
			        { "show": "否", "value":0 }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
            name: "IsImg",
            fieldLabel: "是否图片",
            xtype: "combo",
            //传入后台真实值value field /value
            editable: false,
            anchor: '90%',
            value: 0,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			        { "show": "是", "value": 1 },
			        { "show": "否", "value":0 }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
            name: "Img",
            fieldLabel: "<font color='red'>*</font>图片地址",
            allowBlank: false,
            blankText: "图片地址不能为空",
            regex: /^[\da-zA-Z]{1,150}$/,
            regexText: "请填写1～150个数字或字母"
        }, {
            name: "OrderNum",
            fieldLabel: "<font color='red'>*</font>排序数",
            allowBlank: false,
            blankText: "排序数不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "UserId",
            fieldLabel: "<font color='red'>*</font>添加用户ID",
            allowBlank: false,
            blankText: "添加用户ID不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "ReadGroup",
            fieldLabel: "<font color='red'>*</font>阅读权限",
            allowBlank: false,
            blankText: "阅读权限不能为空",
            regex: /^[\da-zA-Z]{1,9}$/,
            regexText: "请填写1～9个数字或字母"
        }, {
            name: "SourceFrom",
            fieldLabel: "<font color='red'>*</font>来源",
            allowBlank: false,
            blankText: "来源不能为空",
            regex: /^[\da-zA-Z]{1,30}$/,
            regexText: "请填写1～30个数字或字母"
        }, {
            name: "VideoUrl",

            fieldLabel: "<font color='red'>*</font>视频地址",
            allowBlank: false,
            blankText: "视频地址不能为空",
            regex: /^[\w]{1,2147483647}$/,
            regexText: "请填写1～2147483647个数字或字母"
         }, {
            name: "PageSize",
            fieldLabel: "<font color='red'>*</font>显示数量",
            allowBlank: false,
            blankText: "显示数量不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "WriteComment",
            fieldLabel: "<font color='red'>*</font>评论权限",
            allowBlank: false,
            blankText: "评论权限不能为空",
            regex: /^[\da-zA-Z]{1,9}$/,
            regexText: "请填写1～9个数字或字母"
        }, {
            name: "ReadComment",
            fieldLabel: "<font color='red'>*</font>阅读评论权限",
            allowBlank: false,
            blankText: "阅读评论权限不能为空",
            regex: /^[\da-zA-Z]{1,9}$/,
            regexText: "请填写1～9个数字或字母"
        }, {
            name: "AgainstNum",
            fieldLabel: "<font color='red'>*</font>反对数量",
            allowBlank: false,
            blankText: "反对数量不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "SupportNum",
            fieldLabel: "<font color='red'>*</font>支持数",
            allowBlank: false,
            blankText: "支持数不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "Enabled",
            fieldLabel: "是否启用",
            xtype: "combo",
            //传入后台真实值value field /value
            emptyText: '请选择',
            triggerAction: 'query',
            hiddenName: "M_IsSystem",
            readOnly: true,
            mode: "local",
            displayField: "show",
            valueField: "value",
            triggerAction: "all",
            value: "0",
            store: new Ext.data.SimpleStore({
                fields: ["show", "value"],
                data: [["是", "1"], ["否", "0"]]
            })
        }
			]
    });

    var EditModule_VideoWin = new Ext.Window({
        title: "修改视频",
        width: 400,
        height: 450,
       
        layout: "fit",
        //iconCls: "addicon",
        //不可以随意改变大小
        resizable: false,
        //是否可以拖动
        //draggable:false,
        defaultType: "textfield",
        //labelWidth: 100,
        collapsible: true, //允许缩放条
        closeAction: 'destroy',
        closable: true,
        //弹出模态窗体
        modal: 'true',
        buttonAlign: "center",
        bodyStyle: "padding:10px 0 0 15px",
        items: [EditModule_VideoForm],
        listeners: {
            "show": function() {
                if (id && id != "") {
                    //加载表单数据
                    EditModule_VideoForm.form.load(
                                {
                                    url: "/manager/Module_Video/Look/" + id,
                                    method: "get",
                                    success: function(form, action) {

                                    },
                                    failure: function(form, action) {
                                        Ext.Msg.alert("提示信息", "对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            }
        },
        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function() {
                //alert(EditModule_VideoForm.getForm().isValid())
                if (EditModule_VideoForm.getForm().isValid()) {
                    //弹出效果 Ext.MessageBox.alert("asdf");
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function() { }, 1000);
                    EditModule_VideoForm.form.submit({
                        url: "/manager/Module_Video/Update/" + id,
                        method: "POST",
                        success: function(form, action) {
                            //成功后
                             Ext.MessageBox.hide();
                            var flag = action.result.success;
                            if (flag == "true") {
                                Module_VideoStore.loadPage(1);
                               Ext.helper.msg("恭喜", "修改成功!");
                                EditModule_VideoWin.hide();
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.MessageBox.alert("修改失败!", message);
                                }
                                else {
                                    Ext.MessageBox.alert("提示!", "修改失败!");
                                    EditModule_VideoWin.hide();
                                }

                            }
                        },
                        failure: function(form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                            EditModule_VideoWin.hide();
                        }
                    });
                }
            }
        }, {
            text: "重置",
            minWidth: 70,
            qtip: "重置数据",
            handler: function() {
                //加载表单数据
                EditModule_VideoForm.getForm().reset();
                EditModule_VideoForm.form.load(
                                {
                                    url: "/manager/Module_Video/Look/" + id,
                                    method: "get",
                                    success: function(form, action) {
                                    },
                                    failure: function(form, action) {
                                        //Ext.Msg.alert("提示信息","对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function() {
                EditModule_VideoWin.hide();
            }

}]

        });

        EditModule_VideoWin.show();
    }
